<?php
namespace app\manager\controller;
use Endroid\QrCode\QrCode;

class CarRender extends BaseController
{
    protected $check_auths = false; 
    /**
     * GET shwo carrender info list
     * @return [type] [description]
     */
    public function index()
    {
        $list = model('CarRenders')->getCarRendersLists();
        $this->assign('list',$list);
        return view('p/carrender/index');
    }

    /**
     * GET show carrender info
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public function read($id)
    {
        
    }

    /**
     * GET shwo create carrender info
     * @return [type] [description]
     */
    public function create()
    {
        
        return view('p/carrender/create');
    }

    /**
     * POST create new carrender info
     * @return [type] [description]
     */

    public function save()
    {
        
        $post_carrender_info['name'] = input('post.name');
        $post_carrender_info['tel'] = input('post.tel');
        $post_carrender_info['add'] = input('post.add');
        $post_carrender_info['contack'] = input('post.contack');

        $carrender = model('CarRenders')->createCarRender($post_carrender_info);
        
        if($carrender){
            return $this->success(lang('create carrender success'), '/carrender');
        }
            return $this->error(lang('create carrender failed').$carrender['msg']);
        
    }

    /**
     * GET edit carrender info
     * @param  [type] $id [description]
     * @return [type]     [description]
     */

    public function edit($id)
    {
        $data = model('CarRenders')->getcarrenderInfo($id);
        $this->assign('data',$data);
        $this->assign('id',$id);
        return view('p/carrender/edit');
    }

    /**
     * PUT update carrender info
     * @param  [type] $id [description]
     * @return [type]     [description]
     */

    public function update($id)
    {
        $post_carrender_info['name'] = input('post.name');
        $post_carrender_info['tel'] = input('post.tel');
        $post_carrender_info['add'] = input('post.add');
        $post_carrender_info['contack'] = input('post.contack');
        
        $carrender = model('CarRenders')->updateCarRender($id, $post_carrender_info);
        
        if($carrender){
            return $this->success(lang('update carrender success'), '/carrender');
        }
            return $this->error(lang('update carrender failed').$carrender['msg']);

    }
    /**
     * DELETE carrender info
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public function delete($id)
    {
       $ids=input('post.ids/a');
        if (empty($ids)) {
          return $this->error('请选择要删除的选项'); 
        }
        $count = model('CarRenders')->delInfo($ids);
        if ($count) {
           return $this->success('删除成功','/carrender');
        }
        return $this->error('删除失败');
    }

}

